package day04;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 要求用户输入若干员工信息，格式为：
 * name,age,gender,salary,hiredate;name,age,gender,salary,hiredate;....
 * 例如:
 * 张三,25,男,5000,2006-02-15;李四,26,女,6000,2007-12-24;...
 * 然后将每个员工信息解析成Emp对象。并存入到一个集合中。
 * 然后循环集合，输出每一个员工信息(输出使用toString返回的字符串)
 * 然后输出每个员工的转正仪式日期。
 * 转正仪式日期为:入职3个月的当周周五
 * 
 * @author Bonnie
 *
 */
public class Test09 {
    static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    public static void main(String[] args) throws ParseException {

        Scanner scanner = new Scanner(System.in);
        System.out.println("输入员工信息（格式为：张三,25,男,5000,2006-02-15;李四,26,女,6000,2007-12-24;...）");
        String str = scanner.next();
        String[] strs = str.split(";");
        List<Emp> employees = new ArrayList<>();
        for (String s : strs){
            employees.add(getEmp(s));
        }
        for (Emp e : employees){
            System.out.println(e.toString());
            System.out.println("转正仪式日期："+sdf.format(getdate(e.getHiredate())));
        }


    }

    public static Emp getEmp(String s) throws ParseException {
        String[] s1 = s.split(",");
        String name = s1[0];
        int age = Integer.parseInt(s1[1]);
        String gender = s1[2];
        int salary = Integer.parseInt(s1[3]);
        Date date = sdf.parse(s1[4]);
        return new Emp(name,age,gender,salary,date);
    }

    public static Date getdate(Date d){
        Calendar cal = Calendar.getInstance();
         cal.setTime(d);
         cal.add(Calendar.MONTH,3);
         cal.add(Calendar.DAY_OF_WEEK,Calendar.FRIDAY);
        return cal.getTime();
    }
}
